package my.servlet.startup;

import my.servlet.connector.HttpConnector;
import my.servlet.core.container.wrapper.StandardWrapper;
import my.servlet.core.container.wrapper.Wrapper;
import my.servlet.core.loader.Loader;
import my.servlet.core.loader.SimpleLoader;
import my.servlet.core.pipeline.ClientIPLoggerValve;
import my.servlet.core.pipeline.HeaderLoggerValve;
import my.servlet.core.pipeline.Pipeline;
import my.servlet.core.pipeline.Valve;

public final class Bootstrap1 {

    public static void main(String[] args) {

        HttpConnector connector = new HttpConnector();
        Wrapper wrapper = new StandardWrapper();
        wrapper.setServletClass("my.servlet.webroot.ModernServlet");
        Loader loader = new SimpleLoader();
        Valve valve1 = new HeaderLoggerValve();
        Valve valve2 = new ClientIPLoggerValve();

        wrapper.setLoader(loader);
        ((Pipeline) wrapper).addValve(valve1);
        ((Pipeline) wrapper).addValve(valve2);

        connector.setContainer(wrapper);

        try {
            connector.initialize();
            connector.start();

            // make the application wait until we press a key.
            System.in.read();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}